package com.jewaton.auth.commons.entity;


import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 菜单表
 */
@Entity
@Table(name = "MENU")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Menu implements java.io.Serializable {

	private Long mid;
	private String title;
	private String href;
	private Long parentId;
	private Integer types;
	private Boolean isLeaf;
	private Integer sortBy;
	private List<Menu> children =new ArrayList<Menu>();
	private Set<Permission> permissions = new HashSet<Permission>(0);


    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "MID", unique = true, nullable = false, precision = 10, scale = 0)
	public Long getMid() {
		return this.mid;
	}

	public void setMid(Long mid) {
		this.mid = mid;
	}

	@Column(name = "TITLE", nullable = false)
	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "HREF")
	public String getHref() {
		return this.href;
	}

	public void setHref(String href) {
		this.href = href;
	}

	@Column(name = "PARENT_ID", nullable = false, precision = 10, scale = 0)
	public Long getParentId() {
		return this.parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	@Column(name = "TYPES", nullable = false, precision = 1, scale = 0)
	public Integer getTypes() {
		return this.types;
	}

	public void setTypes(Integer types) {
		this.types = types;
	}

	@Column(name = "IS_LEAF", nullable = false)
	public Boolean getIsLeaf() {
		return this.isLeaf;
	}

	public void setIsLeaf(Boolean isLeaf) {
		this.isLeaf = isLeaf;
	}

	@Column(name="SORT_BY")
	public Integer getSortBy() {
	    return sortBy;
	}
	
	public void setSortBy(Integer sortBy) {
	    this.sortBy = sortBy;
	}

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "menu")
	public Set<Permission> getPermissions() {
		return this.permissions;
	}


    public void setPermissions(Set<Permission> permissions) {	
		this.permissions = permissions;
	}
	
	@Transient
	public List<Menu> getChildren() {
		return children;
	}

	public void setChildren(List<Menu> children) {
		this.children = children;
	}

}
